import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.Array;
import java.util.Arrays;

//<E> 代表这个是范型 new对象是往里面传什么类型就只能存储什么类型的数据
class MyArray<E> {
    public E[] array = (E[])new Object[10];

    public E getPos(int pos) {
        return array[pos];
    }
    public void setVal(int pos,E val) {
        this.array[pos] = val;
    }

    @Override
    public String toString() {
        return "MyArray{" +
                "array=" + Arrays.toString(array) +
                '}';
    }
}
class MyArray2<T> {
    public T[] array;


    //通过反射来创建指定数组
    public MyArray2(Class<T> clazz, int capacity) {

        array = (T[]) Array.newInstance(clazz,capacity);
    }
    public void setPos(int pos,T val) {
        this.array[pos] = val;
    }
    public T getVal(int pos) {
        return this.array[pos];
    }
    public T[] getArray() {
        return array;
    }
}

class MyArray3<E extends Number> {

}
public class Test {
    public static void main(String[] args) {

        MyArray2<Integer> myArray2 = new MyArray2<>(Integer.class,10);

        MyArray<String> myArray = new MyArray<String>();
        myArray.setVal(0,"abc");
        myArray.setVal(1,"tiger");
        System.out.println(myArray);
        MyArray<Integer> myArray1 = new MyArray<Integer>();
        myArray1.setVal(0,2);
        myArray1.setVal(1,3);
        System.out.println(myArray1);
    }
}
